/*---------------------------------------------------------------------------------------
| File:
|   xlLoadlib.cpp
| Project:
|   xlCANcontrol, xlMOSTView, xlFlexDemo
|
| Description:
|   For the dynamically linking of the XL Driver Library.
|   
|
|-----------------------------------------------------------------------------
| $Author: vismra $    $Date: 2010-06-08 10:49:03 +0200 (Di, 08 Jun 2010) $   $Revision: 6471 $
| $Id: xlLoadlib.cpp 6471 2010-06-08 08:49:03Z vismra $
|-----------------------------------------------------------------------------
| Copyright (c) 2010 by Vector Informatik GmbH.  All rights reserved.
 ----------------------------------------------------------------------------*/
#include "stdafx.h"
#include <windows.h>
#ifndef _MFC_VER
# include <stdio.h>
#endif
#include "vxlapi.h"



///////////////////////////////////////////////////////////////////////////
//Global variables
////////////////////////////////////////////////////////////////////////////

// function pointers

  XLGETAPPLCONFIG                xlGetApplConfig = NULL;
  XLSETAPPLCONFIG                xlSetApplConfig = NULL;
  XLGETDRIVERCONFIG              xlGetDriverConfig = NULL;
  XLGETCHANNELINDEX              xlGetChannelIndex = NULL;
  XLGETCHANNELMASK               xlGetChannelMask = NULL;
  XLOPENPORT                     xlOpenPort = NULL;
  XLSETTIMERRATE                 xlSetTimerRate = NULL;
  XLRESETCLOCK                   xlResetClock = NULL;
  XLSETNOTIFICATION              xlSetNotification = NULL;
  XLFLUSHRECEIVEQUEUE            xlFlushReceiveQueue = NULL;
  XLGETRECEIVEQUEUELEVEL         xlGetReceiveQueueLevel = NULL;
  XLACTIVATECHANNEL              xlActivateChannel = NULL;
  XLRECEIVE                      xlReceive = NULL;                        
  XLGETEVENTSTRING               xlGetEventString = NULL;
  XLGETERRORSTRING               xlGetErrorString = NULL;
  XLGETSYNCTIME                  xlGetSyncTime = NULL;
  XLGENERATESYNCPULSE            xlGenerateSyncPulse = NULL;
  XLPOPUPHWCONFIG                xlPopupHwConfig = NULL;
  XLDEACTIVATECHANNEL            xlDeactivateChannel = NULL;
  XLCLOSEPORT                    xlClosePort = NULL;
  XLSETTIMERBASEDNOTIFY          xlSetTimerBasedNotify = NULL;  
  XLSETTIMERRATEANDCHANNEL       xlSetTimerRateAndChannel = NULL;
  XLGETLICENSEINFO               xlGetLicenseInfo = NULL;

  // CAN specific functions
  XLCANSETCHANNELOUTPUT          xlCanSetChannelOutput = NULL;    
  XLCANSETCHANNELMODE            xlCanSetChannelMode = NULL; 
  XLCANSETRECEIVEMODE            xlCanSetReceiveMode = NULL; 
  XLCANSETCHANNELTRANSCEIVER     xlCanSetChannelTransceiver = NULL;
  XLCANSETCHANNELPARAMS          xlCanSetChannelParams = NULL;           
  XLCANSETCHANNELPARAMSC200      xlCanSetChannelParamsC200 = NULL;        
  XLCANSETCHANNELBITRATE         xlCanSetChannelBitrate = NULL;   
  XLCANSETCHANNELACCEPTANCE      xlCanSetChannelAcceptance = NULL;       
  XLCANADDACCEPTANCERANGE        xlCanAddAcceptanceRange = NULL;    
  XLCANREMOVEACCEPTANCERANGE     xlCanRemoveAcceptanceRange = NULL; 
  XLCANRESETACCEPTANCE           xlCanResetAcceptance = NULL;   
  XLCANREQUESTCHIPSTATE          xlCanRequestChipState = NULL; 
  XLCANFLUSHTRANSMITQUEUE        xlCanFlushTransmitQueue = NULL;           
  XLCANTRANSMIT                  xlCanTransmit = NULL;

  // LIN specific functions
  XLLINSETCHANNELPARAMS          xlLinSetChannelParams = NULL;
  XLLINSETDLC                    xlLinSetDLC = NULL;
  XLLINSETSLAVE                  xlLinSetSlave = NULL;
  XLLINSENDREQUEST               xlLinSendRequest = NULL;
  XLLINSETSLEEPMODE              xlLinSetSleepMode = NULL;
  XLLINWAKEUP                    xlLinWakeUp = NULL;
  XLLINSETCHECKSUM               xlLinSetChecksum = NULL;
  XLLINSWITCHSLAVE               xlLinSwitchSlave = NULL;


  // IOcab specific functions
  XLDAIOSETPWMOUTPUT             xlDAIOSetPWMOutput = NULL; 
  XLDAIOSETDIGITALOUTPUT         xlDAIOSetDigitalOutput = NULL;
  XLDAIOSETANALOGOUTPUT          xlDAIOSetAnalogOutput = NULL;
  XLDAIOREQUESTMEASUREMENT       xlDAIORequestMeasurement = NULL;
  XLDAIOSETDIGITALPARAMETERS     xlDAIOSetDigitalParameters = NULL;
  XLDAIOSETANALOGPARAMETERS      xlDAIOSetAnalogParameters = NULL;
  XLDAIOSETANALOGTRIGGER         xlDAIOSetAnalogTrigger = NULL;
  XLDAIOSETMEASUREMENTFREQUENCY  xlDAIOSetMeasurementFrequency = NULL;

  // MOST specific functions
  XLFP_MOSTRECEIVE               xlMostReceive = NULL; 
  XLFP_MOSTCTRLTRANSMIT          xlMostCtrlTransmit = NULL;
  XLFP_MOSTSWITCHEVENTSOURCES    xlMostSwitchEventSources = NULL;
  XLFP_MOSTSETALLBYPASS          xlMostSetAllBypass = NULL;
  XLFP_MOSTGETALLBYPASS          xlMostGetAllBypass = NULL;
  XLFP_MOSTSETTIMINGMODE         xlMostSetTimingMode = NULL;
  XLFP_MOSTGETTIMINGMODE         xlMostGetTimingMode = NULL;
  XLFP_MOSTSETFREQUENCY          xlMostSetFrequency = NULL;
  XLFP_MOSTGETFREQUENCY          xlMostGetFrequency = NULL;
  XLFP_MOSTWRITEREGISTER         xlMostWriteRegister = NULL;
  XLFP_MOSTREADREGISTER          xlMostReadRegister = NULL;
  XLFP_MOSTWRITEREGISTERBIT      xlMostWriteRegisterBit = NULL;
  XLFP_MOSTSYNCGETALLOCTABLE     xlMostSyncGetAllocTable = NULL;
  XLFP_MOSTCTRLSYNCAUDIO         xlMostCtrlSyncAudio = NULL;
  XLFP_MOSTCTRLSYNCAUDIOEX       xlMostCtrlSyncAudioEx = NULL;
  XLFP_MOSTSYNCVOLUME            xlMostSyncVolume = NULL;
  XLFP_MOSTSYNCMUTE              xlMostSyncMute = NULL;
  XLFP_MOSTSYNCGETVOLUMESTATUS   xlMostSyncGetVolumeStatus = NULL;
  XLFP_MOSTSYNCGETMUTESTATUS     xlMostSyncGetMuteStatus = NULL;
  XLFP_MOSTGETRXLIGHT            xlMostGetRxLight = NULL; 
  XLFP_MOSTSETTXLIGHT            xlMostSetTxLight = NULL; 
  XLFP_MOSTGETTXLIGHT            xlMostGetTxLight = NULL; 
  XLFP_MOSTSETLIGHTPOWER         xlMostSetLightPower = NULL; 
  XLFP_MOSTGETLOCKSTATUS         xlMostGetLockStatus = NULL; 
  XLFP_MOSTGENERATELIGHTERROR    xlMostGenerateLightError = NULL;
  XLFP_MOSTGENERATELOCKERROR     xlMostGenerateLockError = NULL;
  XLFP_MOSTCTRLRXBUFFER          xlMostCtrlRxBuffer = NULL;
  XLFP_MOSTTWINKLEPOWERLED       xlMostTwinklePowerLed = NULL;
  XLFP_MOSTASYNCTRANSMIT         xlMostAsyncTransmit = NULL; 
  XLFP_MOSTCTRLCONFIGUREBUSLOAD  xlMostCtrlConfigureBusload = NULL;
  XLFP_MOSTCTRLGENERATEBUSLOAD   xlMostCtrlGenerateBusload = NULL;
  XLFP_MOSTASYNCCONFIGUREBUSLOAD xlMostAsyncConfigureBusload = NULL;
  XLFP_MOSTASYNCGENERATEBUSLOAD  xlMostAsyncGenerateBusload = NULL;
  XLFP_MOSTSTREAMOPEN            xlMostStreamOpen = NULL;
  XLFP_MOSTSTREAMCLOSE           xlMostStreamClose = NULL;
  XLFP_MOSTSTREAMSTART           xlMostStreamStart = NULL;
  XLFP_MOSTSTREAMSTOP            xlMostStreamStop = NULL;
  XLFP_MOSTSTREAMBUFFERALLOCATE  xlMostStreamBufferAllocate = NULL;
  XLFP_MOSTSTREAMBUFFERDEALLOCATEALL xlMostStreamBufferDeallocateAll = NULL;
  XLFP_MOSTSTREAMBUFFERSETNEXT   xlMostStreamBufferSetNext = NULL;
  XLFP_MOSTSTREAMGETINFO         xlMostStreamGetInfo = NULL;
  XLFP_MOSTSTREAMBUFFERCLEARALL  xlMostStreamBufferClearAll = NULL;

  // FlexRay specific functions
  XLFP_FRSETCONFIGURATION        xlFrSetConfiguration = NULL; 
  XLFP_FRGETCHANNELCONFIGURATION xlFrGetChannelConfiguration = NULL;
  XLFP_FRSETMODE                 xlFrSetMode = NULL;               
  XLFP_FRINITSTARTUPANDSYNC      xlFrInitStartupAndSync = NULL;         
  XLFP_FRSETUPSYMBOLWINDOW       xlFrSetupSymbolWindow = NULL;     
  XLFP_FRRECEIVE                 xlFrReceive = NULL;               
  XLFP_FRTRANSMIT                xlFrTransmit = NULL;              
  XLFP_FRSETTRANSCEIVERMODE      xlFrSetTransceiverMode = NULL; 
  XLFP_FRSENDSYMBOLWINDOW        xlFrSendSymbolWindow = NULL; 
  XLFP_FRACTIVATESPY             xlFrActivateSpy = NULL;
    
  //Local variables
  static XLCLOSEDRIVER           xlDllCloseDriver = NULL;
  static XLOPENDRIVER            xlDllOpenDriver = NULL;
  
  static HINSTANCE               hxlDll;
 
////////////////////////////////////////////////////////////////////////////

//! canLoadLibrary()

//! Loads CAN API functions from DLL
//!
////////////////////////////////////////////////////////////////////////////

XLstatus xlLoadLibrary(char *library){

  if (!hxlDll)
    hxlDll = LoadLibrary(library);
  
  if (!hxlDll){
#ifdef _MFC_VER
    MessageBox(NULL,"Dynamic XL Driver Library - not found (vxlapi.dll)","XL API",MB_OK|MB_ICONEXCLAMATION);
#else
    printf("Dynamic XL Driver Library - not found (vxlapi.dll)\n");
#endif
    return XL_ERROR;
  } else {
    unsigned char NotFoundAll = 0;
    
    if ( (xlDllOpenDriver           = (XLOPENDRIVER)GetProcAddress(hxlDll,"xlOpenDriver") )==NULL)                               NotFoundAll= 1;
    if ( (xlDllCloseDriver          = (XLCLOSEDRIVER)GetProcAddress(hxlDll,"xlCloseDriver") )==NULL)                             NotFoundAll= 2;
                                                                                                                                  
    // bus independed functions                                                                                                   
    if ( (xlGetApplConfig           = (XLGETAPPLCONFIG)GetProcAddress(hxlDll,"xlGetApplConfig") )==NULL)                         NotFoundAll= 3;
    if ( (xlSetApplConfig           = (XLSETAPPLCONFIG)GetProcAddress(hxlDll,"xlSetApplConfig") )==NULL)                         NotFoundAll= 4;
    if ( (xlGetDriverConfig         = (XLGETDRIVERCONFIG)GetProcAddress(hxlDll,"xlGetDriverConfig") )==NULL)                     NotFoundAll= 5;
    if ( (xlGetChannelIndex         = (XLGETCHANNELINDEX)GetProcAddress(hxlDll,"xlGetChannelIndex") )==NULL)                     NotFoundAll= 6;
    if ( (xlGetChannelMask          = (XLGETCHANNELMASK)GetProcAddress(hxlDll,"xlGetChannelMask") )==NULL)                       NotFoundAll= 7;
    if ( (xlOpenPort                = (XLOPENPORT)GetProcAddress(hxlDll,"xlOpenPort") )==NULL)                                   NotFoundAll= 8;    
    if ( (xlSetTimerRate            = (XLSETTIMERRATE)GetProcAddress(hxlDll,"xlSetTimerRate") )==NULL)                           NotFoundAll= 9;    
    if ( (xlResetClock              = (XLRESETCLOCK)GetProcAddress(hxlDll,"xlResetClock") )==NULL)                               NotFoundAll=10;
    if ( (xlSetNotification         = (XLSETNOTIFICATION)GetProcAddress(hxlDll,"xlSetNotification") )==NULL)                     NotFoundAll=11;
    if ( (xlFlushReceiveQueue       = (XLFLUSHRECEIVEQUEUE)GetProcAddress(hxlDll,"xlFlushReceiveQueue") )==NULL)                 NotFoundAll=12;
    if ( (xlGetReceiveQueueLevel    = (XLGETRECEIVEQUEUELEVEL)GetProcAddress(hxlDll,"xlGetReceiveQueueLevel") )==NULL)           NotFoundAll=13;
    if ( (xlActivateChannel         = (XLACTIVATECHANNEL)GetProcAddress(hxlDll,"xlActivateChannel") )==NULL)                     NotFoundAll=14;
    if ( (xlReceive                 = (XLRECEIVE)GetProcAddress(hxlDll,"xlReceive") )==NULL)                                     NotFoundAll=15;
    if ( (xlGetEventString          = (XLGETEVENTSTRING)GetProcAddress(hxlDll,"xlGetEventString") )==NULL)                       NotFoundAll=16;
    if ( (xlGetErrorString          = (XLGETERRORSTRING)GetProcAddress(hxlDll,"xlGetErrorString") )==NULL)                       NotFoundAll=17;
    if ( (xlGenerateSyncPulse       = (XLGENERATESYNCPULSE)GetProcAddress(hxlDll,"xlGenerateSyncPulse") )==NULL)                 NotFoundAll=18;
    if ( (xlGetSyncTime             = (XLGETSYNCTIME) GetProcAddress(hxlDll,"xlGetSyncTime") )==NULL)                            NotFoundAll=19;
    if ( (xlPopupHwConfig           = (XLPOPUPHWCONFIG)GetProcAddress(hxlDll,"xlPopupHwConfig") )==NULL)                         NotFoundAll=20;
    if ( (xlDeactivateChannel       = (XLDEACTIVATECHANNEL)GetProcAddress(hxlDll,"xlDeactivateChannel") )==NULL)                 NotFoundAll=21;
    if ( (xlClosePort               = (XLCLOSEPORT )GetProcAddress(hxlDll,"xlClosePort") )==NULL)                                NotFoundAll=22;
    if ( (xlSetTimerBasedNotify     = (XLSETTIMERBASEDNOTIFY)GetProcAddress(hxlDll,"xlSetTimerBasedNotify") )==NULL)             NotFoundAll=110;
    if ( (xlSetTimerRateAndChannel  = (XLSETTIMERRATEANDCHANNEL) GetProcAddress(hxlDll, "xlSetTimerRateAndChannel") )==NULL)     NotFoundAll=111;
    if ( (xlGetLicenseInfo          = (XLGETLICENSEINFO) GetProcAddress(hxlDll, "xlGetLicenseInfo") )==NULL)                     NotFoundAll=112;
   
    // CAN specific functions
    if ( (xlCanSetChannelOutput     = (XLCANSETCHANNELOUTPUT)GetProcAddress(hxlDll,"xlCanSetChannelOutput") )==NULL)             NotFoundAll=23;
    if ( (xlCanSetChannelMode       = (XLCANSETCHANNELMODE)GetProcAddress(hxlDll,"xlCanSetChannelMode") )==NULL)                 NotFoundAll=24;
    if ( (xlCanSetReceiveMode       = (XLCANSETRECEIVEMODE)GetProcAddress(hxlDll,"xlCanSetReceiveMode") ) == NULL)               NotFoundAll=25; 
    if ( (xlCanSetChannelTransceiver= (XLCANSETCHANNELTRANSCEIVER)GetProcAddress(hxlDll,"xlCanSetChannelTransceiver") ) == NULL) NotFoundAll=26;
    if ( (xlCanSetChannelParams     = (XLCANSETCHANNELPARAMS)GetProcAddress(hxlDll,"xlCanSetChannelParams") ) == NULL)           NotFoundAll=27;
    if ( (xlCanSetChannelParamsC200 = (XLCANSETCHANNELPARAMSC200)GetProcAddress(hxlDll,"xlCanSetChannelParamsC200") )==NULL)     NotFoundAll=28;
    if ( (xlCanSetChannelBitrate    = (XLCANSETCHANNELBITRATE)GetProcAddress(hxlDll,"xlCanSetChannelBitrate") )==NULL)           NotFoundAll=29; 
    if ( (xlCanSetChannelAcceptance = (XLCANSETCHANNELACCEPTANCE)GetProcAddress(hxlDll,"xlCanSetChannelAcceptance") )==NULL)     NotFoundAll=30;
    if ( (xlCanAddAcceptanceRange   = (XLCANADDACCEPTANCERANGE)GetProcAddress(hxlDll,"xlCanAddAcceptanceRange") )==NULL)         NotFoundAll=31;
    if ( (xlCanRemoveAcceptanceRange= (XLCANREMOVEACCEPTANCERANGE)GetProcAddress(hxlDll,"xlCanRemoveAcceptanceRange") )==NULL)   NotFoundAll=32;
    if ( (xlCanResetAcceptance	    = (XLCANRESETACCEPTANCE)GetProcAddress(hxlDll,"xlCanResetAcceptance") )==NULL)               NotFoundAll=33;
    if ( (xlCanRequestChipState     = (XLCANREQUESTCHIPSTATE)GetProcAddress(hxlDll,"xlCanRequestChipState") )==NULL)             NotFoundAll=34;
    if ( (xlCanFlushTransmitQueue	= (XLCANFLUSHTRANSMITQUEUE)GetProcAddress(hxlDll,"xlCanFlushTransmitQueue") )==NULL)         NotFoundAll=35;  
    if ( (xlCanTransmit             = (XLCANTRANSMIT)GetProcAddress(hxlDll,"xlCanTransmit") )==NULL)                             NotFoundAll=36;                 
    
    // LIN specific functions
    if ( (xlLinSetChannelParams     = (XLLINSETCHANNELPARAMS)GetProcAddress(hxlDll,"xlLinSetChannelParams") )==NULL)             NotFoundAll=37;
    if ( (xlLinSetDLC               = (XLLINSETDLC)GetProcAddress(hxlDll,"xlLinSetDLC") )==NULL)                                 NotFoundAll=38;
    if ( (xlLinSetSlave             = (XLLINSETSLAVE)GetProcAddress(hxlDll,"xlLinSetSlave") )==NULL)                             NotFoundAll=39;
    if ( (xlLinSendRequest          = (XLLINSENDREQUEST)GetProcAddress(hxlDll,"xlLinSendRequest") )==NULL)                       NotFoundAll=40;
    if ( (xlLinWakeUp               = (XLLINWAKEUP) GetProcAddress(hxlDll,"xlLinWakeUp") )==NULL)                                NotFoundAll=41;
    if ( (xlLinSetChecksum          = (XLLINSETCHECKSUM) GetProcAddress(hxlDll,"xlLinSetChecksum") )==NULL)                      NotFoundAll=42;
    if ( (xlLinSwitchSlave          = (XLLINSWITCHSLAVE) GetProcAddress(hxlDll,"xlLinSwitchSlave") )==NULL)                      NotFoundAll=43;

    // IOcab specific functions
    if ( (xlDAIOSetPWMOutput        = (XLDAIOSETPWMOUTPUT)GetProcAddress(hxlDll,"xlDAIOSetPWMOutput") )==NULL)                   NotFoundAll=44;
    if ( (xlDAIOSetDigitalOutput    = (XLDAIOSETDIGITALOUTPUT)GetProcAddress(hxlDll,"xlDAIOSetDigitalOutput") )==NULL)           NotFoundAll=45;
    if ( (xlDAIOSetAnalogOutput     = (XLDAIOSETANALOGOUTPUT)GetProcAddress(hxlDll,"xlDAIOSetAnalogOutput") )==NULL)             NotFoundAll=46;
    if ( (xlDAIORequestMeasurement  = (XLDAIOREQUESTMEASUREMENT)GetProcAddress(hxlDll,"xlDAIORequestMeasurement") )==NULL)       NotFoundAll=47;
    if ( (xlDAIOSetDigitalParameters= (XLDAIOSETDIGITALPARAMETERS) GetProcAddress(hxlDll,"xlDAIOSetDigitalParameters") )==NULL)  NotFoundAll=48;
    if ( (xlDAIOSetAnalogParameters = (XLDAIOSETANALOGPARAMETERS)GetProcAddress(hxlDll,"xlDAIOSetAnalogParameters") )==NULL)     NotFoundAll=49;
    if ( (xlDAIOSetAnalogTrigger    = (XLDAIOSETANALOGTRIGGER) GetProcAddress(hxlDll,"xlDAIOSetAnalogTrigger") )==NULL)          NotFoundAll=50;
    if ( (xlDAIOSetMeasurementFrequency = (XLDAIOSETMEASUREMENTFREQUENCY)GetProcAddress(hxlDll,"xlDAIOSetMeasurementFrequency") )==NULL) NotFoundAll=51;                        
    
    // MOST specific functions
    if ((xlMostReceive              = (XLFP_MOSTRECEIVE) GetProcAddress(hxlDll,"xlMostReceive")) == NULL)                             NotFoundAll=52;
    if ((xlMostCtrlTransmit         = (XLFP_MOSTCTRLTRANSMIT) GetProcAddress(hxlDll,"xlMostCtrlTransmit")) == NULL)                   NotFoundAll=53;
    if ((xlMostSwitchEventSources   = (XLFP_MOSTSWITCHEVENTSOURCES) GetProcAddress(hxlDll,"xlMostSwitchEventSources")) == NULL)       NotFoundAll=54;
    if ((xlMostSetAllBypass         = (XLFP_MOSTSETALLBYPASS) GetProcAddress(hxlDll,"xlMostSetAllBypass")) == NULL)                   NotFoundAll=55;
    if ((xlMostGetAllBypass         = (XLFP_MOSTGETALLBYPASS) GetProcAddress(hxlDll,"xlMostGetAllBypass")) == NULL)                   NotFoundAll=56;
    if ((xlMostSetTimingMode        = (XLFP_MOSTSETTIMINGMODE) GetProcAddress(hxlDll,"xlMostSetTimingMode")) == NULL)                 NotFoundAll=57;
    if ((xlMostGetTimingMode        = (XLFP_MOSTGETTIMINGMODE) GetProcAddress(hxlDll,"xlMostGetTimingMode")) == NULL)                 NotFoundAll=58;
    if ((xlMostSetFrequency         = (XLFP_MOSTSETFREQUENCY) GetProcAddress(hxlDll,"xlMostSetFrequency")) == NULL)                   NotFoundAll=59;
    if ((xlMostGetFrequency         = (XLFP_MOSTGETFREQUENCY) GetProcAddress(hxlDll,"xlMostGetFrequency")) == NULL)                   NotFoundAll=60;
    if ((xlMostWriteRegister        = (XLFP_MOSTWRITEREGISTER) GetProcAddress(hxlDll,"xlMostWriteRegister")) == NULL)                 NotFoundAll=61;
    if ((xlMostReadRegister         = (XLFP_MOSTREADREGISTER) GetProcAddress(hxlDll,"xlMostReadRegister")) == NULL)                   NotFoundAll=62;
    if ((xlMostWriteRegisterBit     = (XLFP_MOSTWRITEREGISTERBIT) GetProcAddress(hxlDll,"xlMostWriteRegisterBit")) == NULL)           NotFoundAll=63;
    if ((xlMostSyncGetAllocTable    = (XLFP_MOSTSYNCGETALLOCTABLE) GetProcAddress(hxlDll,"xlMostSyncGetAllocTable")) == NULL)         NotFoundAll=64;
    if ((xlMostCtrlSyncAudio        = (XLFP_MOSTCTRLSYNCAUDIO) GetProcAddress(hxlDll,"xlMostCtrlSyncAudio")) == NULL)                 NotFoundAll=65;
    if ((xlMostCtrlSyncAudioEx      = (XLFP_MOSTCTRLSYNCAUDIOEX) GetProcAddress(hxlDll,"xlMostCtrlSyncAudioEx")) == NULL)             NotFoundAll=66;
    if ((xlMostSyncVolume           = (XLFP_MOSTSYNCVOLUME) GetProcAddress(hxlDll,"xlMostSyncVolume")) == NULL)                       NotFoundAll=67;
    if ((xlMostSyncMute             = (XLFP_MOSTSYNCMUTE) GetProcAddress(hxlDll,"xlMostSyncMute")) == NULL)                           NotFoundAll=68;
    if ((xlMostSyncGetVolumeStatus  = (XLFP_MOSTSYNCGETVOLUMESTATUS) GetProcAddress(hxlDll,"xlMostSyncGetVolumeStatus")) == NULL)     NotFoundAll=69;
    if ((xlMostSyncGetMuteStatus    = (XLFP_MOSTSYNCGETMUTESTATUS) GetProcAddress(hxlDll,"xlMostSyncGetMuteStatus")) == NULL)         NotFoundAll=70;
    if ((xlMostGetRxLight           = (XLFP_MOSTGETRXLIGHT) GetProcAddress(hxlDll,"xlMostGetRxLight")) == NULL)                       NotFoundAll=71;
    if ((xlMostSetTxLight           = (XLFP_MOSTSETTXLIGHT) GetProcAddress(hxlDll,"xlMostSetTxLight")) == NULL)                       NotFoundAll=72;
    if ((xlMostGetTxLight           = (XLFP_MOSTGETTXLIGHT) GetProcAddress(hxlDll,"xlMostGetTxLight")) == NULL)                       NotFoundAll=73;
    if ((xlMostSetLightPower        = (XLFP_MOSTSETLIGHTPOWER) GetProcAddress(hxlDll,"xlMostSetLightPower")) == NULL)                 NotFoundAll=74;
    if ((xlMostGetLockStatus        = (XLFP_MOSTGETLOCKSTATUS) GetProcAddress(hxlDll,"xlMostGetLockStatus")) == NULL)                 NotFoundAll=75;
    if ((xlMostGenerateLightError   = (XLFP_MOSTGENERATELIGHTERROR) GetProcAddress(hxlDll,"xlMostGenerateLightError")) == NULL)       NotFoundAll=76;
    if ((xlMostGenerateLockError    = (XLFP_MOSTGENERATELOCKERROR) GetProcAddress(hxlDll,"xlMostGenerateLockError")) == NULL)         NotFoundAll=77;
    if ((xlMostCtrlRxBuffer         = (XLFP_MOSTCTRLRXBUFFER) GetProcAddress(hxlDll,"xlMostCtrlRxBuffer")) == NULL)                   NotFoundAll=78;
    if ((xlMostTwinklePowerLed      = (XLFP_MOSTTWINKLEPOWERLED) GetProcAddress(hxlDll,"xlMostTwinklePowerLed")) == NULL)             NotFoundAll=79;
    if ((xlMostAsyncTransmit        = (XLFP_MOSTASYNCTRANSMIT) GetProcAddress(hxlDll,"xlMostAsyncTransmit")) == NULL)                 NotFoundAll=80;
    if ((xlMostCtrlConfigureBusload = (XLFP_MOSTCTRLCONFIGUREBUSLOAD) GetProcAddress(hxlDll,"xlMostCtrlConfigureBusload")) == NULL)   NotFoundAll=81;
    if ((xlMostCtrlGenerateBusload  = (XLFP_MOSTCTRLGENERATEBUSLOAD) GetProcAddress(hxlDll,"xlMostCtrlGenerateBusload")) == NULL)     NotFoundAll=82;
    if ((xlMostAsyncConfigureBusload= (XLFP_MOSTASYNCCONFIGUREBUSLOAD) GetProcAddress(hxlDll,"xlMostAsyncConfigureBusload")) == NULL) NotFoundAll=83;
    if ((xlMostAsyncGenerateBusload = (XLFP_MOSTASYNCGENERATEBUSLOAD) GetProcAddress(hxlDll,"xlMostAsyncGenerateBusload")) == NULL)   NotFoundAll=84;   
    if ((xlMostStreamOpen           = (XLFP_MOSTSTREAMOPEN) GetProcAddress(hxlDll,"xlMostStreamOpen")) == NULL)                       NotFoundAll=85;   
    if ((xlMostStreamClose          = (XLFP_MOSTSTREAMCLOSE) GetProcAddress(hxlDll,"xlMostStreamClose")) == NULL)                     NotFoundAll=86;   
    if ((xlMostStreamStart          = (XLFP_MOSTSTREAMSTART) GetProcAddress(hxlDll,"xlMostStreamStart")) == NULL)                     NotFoundAll=87;   
    if ((xlMostStreamStop           = (XLFP_MOSTSTREAMSTOP) GetProcAddress(hxlDll,"xlMostStreamStop")) == NULL)                       NotFoundAll=88;
    if ((xlMostStreamBufferAllocate = (XLFP_MOSTSTREAMBUFFERALLOCATE) GetProcAddress(hxlDll,"xlMostStreamBufferAllocate")) == NULL)   NotFoundAll=89;
    if ((xlMostStreamBufferDeallocateAll = (XLFP_MOSTSTREAMBUFFERDEALLOCATEALL) GetProcAddress(hxlDll,"xlMostStreamBufferDeallocateAll")) == NULL)   NotFoundAll=90;
    if ((xlMostStreamBufferSetNext  = (XLFP_MOSTSTREAMBUFFERSETNEXT) GetProcAddress(hxlDll,"xlMostStreamBufferSetNext")) == NULL)     NotFoundAll=91;
    if ((xlMostStreamGetInfo        = (XLFP_MOSTSTREAMGETINFO) GetProcAddress(hxlDll,"xlMostStreamGetInfo")) == NULL)                 NotFoundAll=92;
    if ((xlMostStreamBufferClearAll = (XLFP_MOSTSTREAMBUFFERCLEARALL) GetProcAddress(hxlDll,"xlMostStreamBufferClearAll")) == NULL)   NotFoundAll=93;

    // FlexRay specific functions
    if ((xlFrSetConfiguration       = (XLFP_FRSETCONFIGURATION) GetProcAddress(hxlDll,"xlFrSetConfiguration")) == NULL)               NotFoundAll=100;  
    if ((xlFrGetChannelConfiguration= (XLFP_FRGETCHANNELCONFIGURATION) GetProcAddress(hxlDll,"xlFrGetChannelConfiguration")) == NULL) NotFoundAll=101;  
    if ((xlFrSetMode                = (XLFP_FRSETMODE) GetProcAddress(hxlDll,"xlFrSetMode")) == NULL)                                 NotFoundAll=102;  
    if ((xlFrInitStartupAndSync     = (XLFP_FRINITSTARTUPANDSYNC) GetProcAddress(hxlDll,"xlFrInitStartupAndSync")) == NULL)           NotFoundAll=103;  
    if ((xlFrSetupSymbolWindow      = (XLFP_FRSETUPSYMBOLWINDOW) GetProcAddress(hxlDll,"xlFrSetupSymbolWindow")) == NULL)             NotFoundAll=104;  
    if ((xlFrReceive                = (XLFP_FRRECEIVE) GetProcAddress(hxlDll,"xlFrReceive")) == NULL)                                 NotFoundAll=105;  
    if ((xlFrTransmit               = (XLFP_FRTRANSMIT) GetProcAddress(hxlDll,"xlFrTransmit")) == NULL)                               NotFoundAll=106;  
    if ((xlFrSetTransceiverMode     = (XLFP_FRSETTRANSCEIVERMODE) GetProcAddress(hxlDll,"xlFrSetTransceiverMode")) == NULL)           NotFoundAll=107; 
    if ((xlFrSendSymbolWindow       = (XLFP_FRSENDSYMBOLWINDOW) GetProcAddress(hxlDll,"xlFrSendSymbolWindow")) == NULL)               NotFoundAll=108; 
    if ((xlFrActivateSpy            = (XLFP_FRACTIVATESPY) GetProcAddress(hxlDll,"xlFrActivateSpy")) == NULL)                         NotFoundAll=109;
    
    if (NotFoundAll) {
      return XL_ERROR;
    }
  }
  return XL_SUCCESS;
}

////////////////////////////////////////////////////////////////////////////

//! canUnloadLibrary()

//! Unload XL API DLL
//!
////////////////////////////////////////////////////////////////////////////

XLstatus xlUnloadLibrary(void){  
  if (hxlDll) {
    FreeLibrary( hxlDll );
    hxlDll = 0;
  }
  return XL_SUCCESS;
}

////////////////////////////////////////////////////////////////////////////

//! xlOpenDriver()

//! Automatically loads DLL and then opens driver
//!
////////////////////////////////////////////////////////////////////////////

XLstatus xlOpenDriver(void){
  
#ifdef WIN64
  if (xlLoadLibrary("vxlapi64")!=XL_SUCCESS) return XL_ERR_CANNOT_OPEN_DRIVER;
#else
  if (xlLoadLibrary("vxlapi")!=XL_SUCCESS) return XL_ERR_CANNOT_OPEN_DRIVER;
#endif
  return xlDllOpenDriver();
}

////////////////////////////////////////////////////////////////////////////

//! xlCloseDriver()

//! Automatically close DLL
//!
////////////////////////////////////////////////////////////////////////////

XLstatus xlCloseDriver(void){
  xlDllCloseDriver();
  return xlUnloadLibrary();
}

